import { Types, defineComponent, type IWorld, type Entity, type Component } from '$lib/ecs';

const stats = new Map();

export const defineStat = (stat) => {
  const comp = defineComponent(stat, {
    amount: Types.i32,
  });
  stats.set(stat, comp);
  return comp;
};

export const Dexterity = defineStat('Dexterity');
export const Agility = defineStat('Agility');
export const Strength = defineStat('Strength');
export const Intelligence = defineStat('Intelligence');

export const FreeStats = defineComponent('FreeStats', {
  amount: Types.i32,
});

export const enumStats = () => Array.from(stats.entries());

export const getStatLevel = (world: IWorld, e: Entity, stat: Component) => {
  return stat.amount[e];
};
